<?php

// R0910CMS 
// created by TLightSky
// time : 20100226

if(!defined("IN_R0910CMS")) {
    exit("Access Denied!");
}

class R_Db_SQLMaker_Update extends R_Db_SQLMakerAbstract {
    public $tableName = null;
    public $where     = null;
    public $set       = null;
    public $limit     = null;
    //UPDATE `test1` SET `age`='14' WHERE (`id`='0') LIMIT 1;
    public function makeSQL() {
        $this->checkNotNull(array(
            'tableName', 'where', 'set',
            ) //end of the array
        );
        $t1 = "UPDATE ".$this->addSlash1($this->tableName);
        $t2 = $this->makeSet($this->set);
        $t3 = $this->makeWhere($this->where);

        $t4 = '';
        if(!empty($this->limit)) {
            $t4 = $this->makeLimit($this->limit);
        }
        

        /*
         */
        $this->_sql = join("",array($t1,$t2,$t3,$t4,));
        return $this->_sql;
    }


    public function makeSet($set) {
        $t3 = " SET ";
        if(is_array($set)) {
            $wh = array();
            foreach($set as $k => $v ) {
                $wh[] = $this->addSlash1($k)."=".$this->addSlash3($v);
            }
            $t3.=join(" ,", $wh);
        } else if(is_string($set)){
            $t3.= $set;
        } else {
            throw new R_Db_Exception('Set should be a string or an arrary.');
        }
        return $t3;
    }    
}
